<?php defined( 'BASEPATH' ) or die( 'Restricted' );
/*
This code is Copyright (C) by TMLA INC.  ALL RIGHTS RESERVED.
Please view license.txt in /tgsf_core/legal/license.txt or
http://tgWebSolutions.com/opensource/tgsf/license.txt
for complete licensing information.
*/
load_library('parser/tgsfParser',IS_CORE);

class parserFactory extends tgsfBase
{
	public static function fixedLengthField()
	{
		return new fixedLengthFieldParser();
	}
}

class fixedLengthFieldDefinition extends tgsfBase
{
	protected $_ro_start;
	protected $_ro_length;
	protected $_ro_name; // the field name per a file spec
	//------------------------------------------------------------------------
	/**
	* Set the start value for this field definition
	* @param Int The offset for the start of this field per a file spec
	*/
	public function &start( $value )
	{
		$this->_ro_start = (int)$value;
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* Set the length value for this field definition
	* @param Int The length of this field per a file spec
	*/
	public function &length( $value )
	{
		$this->_ro_length = (int)$value;
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* Set the name of this field
	* @param String The name of this field per a file spec
	*/
	public function &name( $value )
	{
		$this->_ro_name = (string)$value;
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* Sets the value of the line from the file for this field definition
	* The line is passed by reference so that we don't consume memory
	* This means this class should not modify the line
	*/
	public function &line( &$line )
	{
		$this->_ro_line =& $line;
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* Used during parsing to get the field value
	*/
	public function &setDsValue( &$ds )
	{
		$ds->setVar( $this->_ro_name);
		return $this;
	}
	//------------------------------------------------------------------------
	/**
	* returns the value for the field.  This honors trimming
	*/
	public function getValue()
	{
		$value = substr( $this->_ro_line, $this->_ro_start, $this->_ro_stop );

		if ( $this->_ro_doTrim )
		{
			return trim( $value, $this->_ro_trimChars );
		}

		if ( $this->_ro_int )
		{
			$value = (int)$value;
		}

		return $value;
	}
}
//------------------------------------------------------------------------
class fixedLengthFieldParser extends tgsfBaseParser
{

}